;;; ----------------------------------------------------------------------
;;; Makes a replacement EPROM in an Epyx Fast Load cartridge write
;;; bootstrap code into memory before continuing with the normal
;;; C64 RESET code.

	    CODESTART   = $8100
            DEST        = $C000
            P           = $FC
            Q           = $FE

;;; ----------------------------------------------------------------------

            .org 32768
            .word START
            .word $FE47
            .byte $C3,$C2,$CD,$38,$30 ; CBM80

;;; ----------------------------------------------------------------------

START:      jsr copy
	    ;; resume with the regular RESET code
            ;ldx #0
            jmp $FCEF

;;; ----------------------------------------------------------------------

copy:       lda #<CODESTART
            sta P
            lda #>CODESTART
            sta P+1
            lda #<DEST
            sta Q
            lda #>DEST
            sta Q+1
	    ldy #0

loop1:      lda (P),y
            sta (Q),y
            iny
            bne loop1

            inc P+1
            inc Q+1
            lda Q+1
            cmp #208
            bne loop1

            rts

;;; ----------------------------------------------------------------------

	    .align 256, $FF
            .incbin "49152.bin"

align1:     .res 52555 - align1 - 49152 + 32768 + 256, $FF
            .incbin "52555.bin"

;;; ----------------------------------------------------------------------
;;; Restore the EPROM'd contents to memory

restore:    .res 57111 - restore + 32768 - 49152, $FF
            .org 57111

            ldy #0              ; charge up the capacitor
rest1:      inc $DE00
            inc $DE00
            inc $DE00
            dey
            bne rest1

            jsr $FD02
            bne 57111

            jmp copy

;;; ----------------------------------------------------------------------

	    .align 8192, $FF

;;; ----------------------------------------------------------------------

